<!-- page heading start-->
<div class="page-heading">
    <h3>
        财务奖金分配管理系统
    </h3>

</div>
<!-- page heading end-->
<div class="row">
    <div class="col-sm-12">
        <section class="panel">
            <header class="panel-heading">
                <button class="btn btn-primary" data-toggle="modal" data-target="#myModal1" style="float: left">
                    导入
                </button>
                <div class="input-group" style="width: 300px;margin-left: 20%">
                    <input class="form-control input-lg date-picker1"autocomplete="off" name="startdate" id="sdate" value="<?php echo I('get.sdate', '', '');?>"
                           placeholder="请输入要选择的月份">
                    <span class="input-group-addon btn btn-primary" onclick="submit_sdate()">搜索</span>
                </div>

            </header>
            <div class="panel-body">
                <table class="table table-hover general-table table-bordered" style="width: 20%;float: left">
                    <tr>
                        <td><a href="/User/Tool/riches" >全部工作室</a><a class="btn btn-success" href="/User/Tool/room" style="float: right">新增</a></td>
                    </tr>
                    <?php
                foreach($room as $room_v){
                    echo "<tr>
                    <td style='border:0px;'><a href='/User/Tool/riches?room_id=" . $room_v['id'] . "'>" . $room_v['name'] . "</a></td>
                    </tr>";
                    }
                    ?>
                </table>

                <table class="table table-hover general-table table-bordered" style="width: 79%;float: right;">
                    <thead>
                    <tr>
                        <th width="10%">时间</th>
                        <th width="20%">工作室</th>
                        <th width="12%">期初余额</th>
                        <th width="12%">期末余额</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach($list as $val){?>
                    <tr>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $val['year'] . "年" . $val['month'] . "月";?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $val['room_name'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $val['m_start'];?>
                            </span>
                        </td>
                        <td>
                            <span style="word-break:break-all;word-wrap:break-word">
                                <?php echo $val['m_end'];?>
                            </span>
                        </td>
                        <td>
                            <div>
                                <button class="btn btn-success" onclick="return show_dtl(this)"
                                        data-roomId="<?php echo $val['room_id'];?>"
                                        data-roomName="<?php echo $val['room_name'];?>"
                                        data-year="<?php echo $val['year'];?>" data-month="<?php echo $val['month'];?>"
                                        data-m_start="<?php echo $val['m_start'];?>" data-m_end="<?php echo $val['m_end'];?>"
                                        data-income="<?php echo $val['income'];?>" data-pay="<?php echo $val['pay'];?>">
                                    详情
                                </button>
                                <a class="btn btn-danger" href="#"
                                   onclick="<?php echo 'return delete_data(' . $val['id'] .')';?>">删除</a>
                            </div>
                        </td>
                    </tr>
                    <?php }?>

                    </tbody>
                </table>
                <div class="pages">
                    {$page}
                </div>
            </div>
        </section>
    </div>
</div>

<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-body">
                <form enctype="multipart/form-data" action="/User/Tool/richesImport" method="post">
                    <input type="file" name="import">
                    <a href="/Public/file/Book2.xlsx">样例下载</a><input class="btn btn-success" type="submit">
                </form>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>

<div class="modal fade" id="myModal2" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel2">奖金明细</h4>
            </div>
            <div class="modal-body" id="myModal2_body">

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script>
    function show_dtl(e) {
        $("#m_start").val($(e).attr("data-m_start"));
        $("#m_end").val($(e).attr("data-m_end"));
        $("#income").val($(e).attr("data-income"));
        $("#pay").val($(e).attr("data-pay"));

        var table="<table class='table table-hover general-table table-bordered'><tr><th>项目</th><th>金额</th></tr>";
        table += "<tr>";
        table += "<td>" + "期初余额" + "</td>";
        table += "<td>" + $(e).attr("data-m_start") + "</td>";
        table += "</tr>";
        table += "<tr>";
        table += "<td>" + "期末余额" + "</td>";
        table += "<td>" + $(e).attr("data-m_end") + "</td>";
        table += "</tr>";
        table += "<tr>";
        table += "<td colspan='2'>" + "支出" + "</td>";
        table += "</tr>";

        var pay_list = $(e).attr("data-pay").split(";");
        for(var i=0; i<pay_list.length-1;i++){
            var pay_detail = pay_list[i].split(":");
            table += "<tr>";
            table += "<td>" + pay_detail[0] + "</td>";
            table += "<td>" + pay_detail[1] + "</td>";
            table += "</tr>";
        }
        table += "<tr>";
        table += "<td colspan='2'>" + "收入" + "</td>";
        table += "</tr>";
        var income_list = $(e).attr("data-income").split(";");
        for(var j=0; j<income_list.length-1;j++){
            var income_detail = income_list[j].split(":");
            table += "<tr>";
            table += "<td>" + income_detail[0] + "</td>";
            table += "<td>" + income_detail[1] + "</td>";
            table += "</tr>";
        }
        table += "</table>";
        $("#myModal2_body").html(table);
        $('#myModal2').modal('show');
    }
    function delete_data(id) {
        if(confirm("确定删除？")){
            $.ajax({
                data: {id: id},
                dataType: 'json',
                url: '/User/Tool/richesDelete',
                type: 'get',
                success: function (res) {
                    window.location.reload();
                }
            });
        }
        return false;
    }
    function submit_sdate() {
        window.location.href = "/User/Tool/riches?sdate=" + $("#sdate").val() + "&room_id=" + "<?php echo I('get.room_id', '', '');?>";
    }
</script>
<script type="text/javascript" src="/Public/js/laydate/laydate.js"></script>
<style>
    .laydate_table {
        display: none;
    }

    #laydate_hms {
        display: none !important;
    }
</style>
<script type="text/javascript">
    $(".date-picker").bind("click", function () {
        laydate({
            format: 'YYYY/MM',
            min: laydate.now(), //设定最小日期为当前日期
            max: '2099-06', //最大日期
            istime: true,
            istoday: false
        });
        laydate.skin("molv");
    });
    $(".date-picker1").bind("click", function () {
        laydate({
            format: 'YYYYMM',
            max: '2099-06', //最大日期
            istime: true,
            istoday: false
        });
        laydate.skin("molv");
    });
</script>